﻿using System;
using System.Security.Cryptography;

namespace mycalendar
{
    /// <summary>
    /// 输出今年的日历
    /// </summary>
    internal class Program
    {
        const int theMonthHeight = 10;
        const int theMonthWidth = 40;
        const int theDayWidth = 4;
        static void Main(string[] args)
        {
            //定义一个变量为1月1日
            DateTime theDay = new DateTime(2022, 1, 1);
            //输出月份框架
            for (int month = 1; month < 13; month++)
            {
                string s1 = "月";
                string s2 = "日  一  二  三  四  五  六";
                int x = (month - 1) % 3 * theMonthWidth;
                int y = (month - 1) / 3 * theMonthHeight;
                Console.SetCursorPosition(x+18, y);
                //输出月份
                Console.Write(month);
                Console.WriteLine(s1);
                //输出 "日  一  二  三  四  五  六"
                Console.SetCursorPosition(x, y+1);
                Console.Write(s2);


            }
            int x1 = 0, y1 = 0;
            do
            {//确定一号位置
                if(theDay.Day==1)
                {
                    x1 = (int)theDay.DayOfWeek * theDayWidth + (theDay.Month - 1) % 3 * theMonthWidth;
                    y1 = (theDay.Month - 1) / 3 * theMonthHeight;
                    Console.SetCursorPosition(x1, y1 + 2);
                    Console.Write("{0,2} ",theDay.Day);
                }//确定其他日期的位置
                if(theDay.Day!=1)
                {
                    //确认是否为周日
                    if(theDay.DayOfWeek==0)
                    {
                        x1= (theDay.Month - 1) % 3 * theMonthWidth;
                        y1++;
                             }
                    else
                    {
                        x1 = x1 + theDayWidth;
                    }//输出其他日期
                    Console.SetCursorPosition(x1, y1 + 2);
                    Console.Write("{0,2}",theDay.Day);
                }
                theDay = theDay.AddDays(1);
                //设定终止条件
            } while (theDay.Year==2022);
            Console.ReadKey();

        }
    }
}
